<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" "pack11template">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    </head>
    <body>
<form action="info.php" method="POST" enctype="multipart/form-data">
    <input type="file" name="file"/>
    <input type="hidden" name="VisitorName" value="Vit"/><br/>
    <input type="Submit"/><br/>
</form>
<?php
error_reporting (E_ALL);
function alist ($array) {  //This function prints a text array as an html list.
  $alist = "<ul>";
  for ($i = 0; $i < sizeof($array); $i++) {
    $alist .= "<li>$array[$i]";
  }
  $alist .= "</ul>";
  return $alist;
}
exec("convert -version", $out, $rcode); //Try to get ImageMagick "convert" program version number.
echo "Version return code is $rcode <br>"; //Print the return code: 0 if OK, nonzero if error.
echo alist($out); //Print the output of "convert -version"
//Additional code discussed below goes here.

echo "-----Find the path to ImageMagicks convert comand <br/>";
system("type convert");
echo "<BR/>-----Alternate method <br/>";
system('which convert',$path);
echo "<br/>-----<br/>";
if(is_array($path)) {
    print_r($path);
} else {
    echo $path;
}
echo "<br/>-----<br/>";

$array=array();
echo "<br/>-----<br/>";
exec("/usr/local/bin/convert /home/clients/webs/vit/tessmann/dekaro/pdf/pdftest.pdf /home/clients/webs/vit/tessmann/dekaro/pdf/pdftest.jpg 2>&1",$array);
//exec("convert mac_mini.jpg mac_mini.png 2>&1", $array);
echo "<br>".print_r($array)."<br>";
echo "<br/>-----<br/>";

echo "<br/>-----Which<br/>";
system('whereis convert',$path);
print_r($path);
echo "<br/>-----<br/>";


if(array_key_exists("VisitorName",$_POST)) {
    print_r($_FILES);

if ($_FILES["file"]["type"] == "application/pdf") {
                if ($_FILES["file"]["error"] > 0) {
                    return "Return Code: " . $_FILES["file"]["error"];
                } else {
                    move_uploaded_file($_FILES["file"]["tmp_name"],"pdftest.pdf") or die("cant move uploaded file");
                }
          }

    $convert="/usr/local/bin/convert";
    $file1 = "pdf/pdftest.pdf";
    $file2 = "pdf/pdftest.jpg";
    //$result = system("convert $file1 $file2",$retval);
    $result = exec("convert /home/clients/webs/vit/tessmann/dekaro/pdf/pdftest.pdf /home/clients/webs/vit/tessmann/dekaro/pdf/pdftest.jpg 2>&1",$retval);

    if(is_array($retval)) {
        print_r($retval);
    } else {
        echo $retval."<br/>";
    }

    echo "<img src='pdf/pdftest.jpg'/><br/>";
    print_r(error_get_last());
} else {
    echo "Not a PDF!<br/>";
}

phpinfo();

?>
    </body>
</html>